<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "System/Date.class.php");
$date = new Date();

require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "System/MuDatabase.class.php");
$db = new MuDatabase();

require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "System/Account.class.php");
$acc = new Account($db);

require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "System/Guild.class.php");
$gd = new Guild();

require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "System/Character.class.php");
$ch = new Character();

/* CASTLE SIEGE */
require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "System/Guild.class.php");
$gd = new Guild();

$db->Query("SELECT g.G_Name,g.G_Master,g.G_Mark,cs.Points,g.Number FROM Guild g, Z_CastleSiegeWins cs WHERE g.G_Name = cs.Guild AND g.G_Name = (SELECT OWNER_GUILD FROM MuCastle_DATA)");

if ($db->NumRows() > 0) {
    $data = $db->GetRow();
    $CSOwner = $data[0];
    $CSKing = $data[1];
    $CSMark = $gd->PrintGuildMark(bin2hex($data[2]), 85);
    $CSWins = $data[3];
    $CSOwnersNumber = $data[4];

    $db->Query("SELECT g.G_Name, COUNT(m.G_Name) FROM Guild g, GuildMember m WHERE g.G_Name = m.G_Name AND g.G_Union = '$CSOwnersNumber' GROUP BY g.G_Name");
    $NumAllies = $db->NumRows();
    $CSAllies = array();
    $CSMembers = 0;
    for ($i = 0; $i < $NumAllies; $i++) {
        $result = $db->GetRow();
        if ($result[0] != $CSOwner)
            $CSAllies[$i] = $result[0];
        $CSMembers += $result[1];
    }
}
else {
    $CSOwner = "-";
    $CSKing = "-";
    $CSMark = "";
    $CSWins = "-";
    $CSAllies = array();
    $CSMembers = "-";
}

$db->Query("SELECT DATEADD(day, -1, SIEGE_END_DATE) FROM MuCastle_DATA");
$data = $db->GetRow();

$dateClass = new Date();
$NextCSDate = $dateClass->DateFormat($data[0]);
///////////////////// 
// RANKINGS TOP 5
$db->Query("SELECT TOP 1 AccountID,Name,ResetCount FROM Character ORDER BY ResetCount DESC");
$resets = $db->GetRow();

$db->Query("SELECT TOP 1 AccountID,Name,ResetCount FROM Character ORDER BY ResetCount DESC");
$resetsday = $db->GetRow();

$db->Query("SELECT TOP 1 AccountID,Name,ResetCount FROM Character ORDER BY ResetCount DESC");
$resetsweek = $db->GetRow();

$db->Query("SELECT TOP 1 AccountID,Name,ResetCount FROM Character ORDER BY ResetCount DESC");
$resetsmonth = $db->GetRow();

$db->Query("SELECT TOP 1 AccountID,Name,MasterResetCount FROM Character ORDER BY MasterResetCount DESC");
$grandresets = $db->GetRow();

$db->Query("SELECT TOP 1 AccountID,Name,OnlineHours FROM MEMB_STAT ORDER BY OnlineHours DESC");
$online = $db->GetRow();
?>
<?php require ("Templates/F-Team/config/F-Team.php"); ?>
<div id="maincenterTop"></div>
          <div id="maincenter">     
          <div class="slide_top"></div>
          <div class="slide_meio">
          <div class="rslides_container">
      <ul class="rslides" id="slider1">
        <li><img src="<?php echo $SLIDE_LINK['1']; ?>" alt=""></li>
        <li><img src="<?php echo $SLIDE_LINK['2']; ?>" alt=""></li>
        <li><img src="<?php echo $SLIDE_LINK['3']; ?>" alt=""></li>
      </ul>
	    </div>
    	</div>
          <div class="slide_footer"></div>  
                  <br /><br />   
            <!-- NOTICE & EVENTS -->
				<div class="noticias_top"></div>
				<div class="noticias_centro">
				<div class="noticias_titulo"></div>
        <?php
                $db->Query("SELECT TOP 5 * FROM Z_News WHERE archive = 0 ORDER BY stick DESC, [order] ASC");
                $NewNumRows = $db->NumRows();
                if ($NewNumRows > 1):
                    for ($n = 0; $n < $NewNumRows; $n++):
                        $New = $db->GetRow();
                        $n + 1;
                        ?><?php
                            if (substr($New['link'], 0, 7) != "" && strlen($New['link']) > 12):
                                $NewLink = "
                <li><div class='notice_seta'></div><div class='notice_estrela'></div><div class='notice_bg'><a href='{$New['link']}'>{$New['title']}</a></div><div class='notice_databg'><div class='notice_data'>{$date->DateFormat($New['date'])}</div></div></li>";
                            endif;
                            ?>
                            <?php echo $NewLink; ?>
                            <?php
                    endfor;
                else:
                    $Name = ($acc->memb_name ? $acc->memb_name : 'Visitante');
                    echo "<li><b>OPSSS</b> {$Name},  Não existe nenhuma noticia no momento, volte mais tarde Obrigado :) !</li>";
                endif;
                ?>
				<br/>
				</div>
				<div class="noticias_footer">
                <a class="" href="?page=readNotice"><div class="button_mais"></div></a>
                </div>
			<!-- Top Servidor --> 
			<!--<br />
			<div class="top"></div>
				<div class="top_meio">
			<table>
            
			</table>
			<br/>
			</div>
				<div class="top_footer">
				<ul>
                <a class="" href="?page=rankings&amp;type=1&amp;top=10&amp;period=0"><li class="button_mais"></li></a>
                </ul></div>
			<br />-->

			<div class="ranking_top"></div>
			<div class="ranking_meio"><br /><table width="525" border="0" align="center" cellpadding="1" cellspacing="1">
      <tr>
        <td align="center" class="rank_status"><h1><span></span>PK</h1></td>
        <td align="center" class="rank_status"><h1><span></span>Resets Geral</h1></td>
        <td align="center" class="rank_status"><h1><span></span>Resets Semanal</h1></td>
		    <td align="center" class="rank_status"><h1><span></span>Resets Mensal</h1></td>
		    <td align="center" class="rank_status"><h1><span></span>Master Resets</h1></td>
      </tr>
      <tr>
        <td align="center" class="rank_status">
          <?php
            $db->Query("SELECT TOP 1 AccountID,Name,".$COLUMN_PK." FROM Character ORDER BY ".$COLUMN_PK." DESC");
            {
            ?>
            <?php echo $acc->GetAccountImage($db->GetRow('AccountID'), $db, 70, 70); ?>
            <?php } ?>
        </td>
        <td align="center" class="rank_status">
          <?php
            $db->Query("SELECT TOP 1 AccountID,Name,".$COLUMN_RESET_DAY." FROM Character ORDER BY ".$COLUMN_RESET_DAY." DESC");
            {
            ?>
            <?php echo $acc->GetAccountImage($db->GetRow('AccountID'), $db, 70, 70); ?>
            <?php } ?>
        </td>
        <td align="center" class="rank_status">
          <?php
            $db->Query("SELECT TOP 1 AccountID,Name,".$COLUMN_RESET_WEEK." FROM Character ORDER BY ".$COLUMN_RESET_WEEK." DESC");
            {
            ?>
            <?php echo $acc->GetAccountImage($db->GetRow('AccountID'), $db, 70, 70); ?>
            <?php } ?>
        </td>
        <td align="center" class="rank_status">
          <?php
            $db->Query("SELECT TOP 1 AccountID,Name,".$COLUMN_RESET_MONTH." FROM Character ORDER BY ".$COLUMN_RESET_MONTH." DESC");
            {
            ?>
            <?php echo $acc->GetAccountImage($db->GetRow('AccountID'), $db, 70, 70); ?>
            <?php } ?>
        </td>
        <td align="center" class="rank_status">
          <?php
            $db->Query("SELECT TOP 1 AccountID,Name,".$COLUMN_MASTER_RESET." FROM Character ORDER BY ".$COLUMN_MASTER_RESET." DESC");
            {
            ?>
            <?php echo $acc->GetAccountImage($db->GetRow('AccountID'), $db, 70, 70); ?>
            <?php } ?>
        </td>
      </tr>
      </table><br /><br />
<div class="premio1"><p>5 <span style="font-size:14px;">Cashs</span></p></div>
<div class="premio2"><p>3 <span style="font-size:14px;">Cashs</span></p></div>
<div class="premio3"><p>1 <span style="font-size:14px;">Cashs</span></p></div>
</div>
<div class="ranking_fim">
<a class="" href="?c=Rankings"><div class="button_mais"></div></a>
</div>
				<div class="siege">
<div style="margin-left:425px; margin-top:47px; position:absolute;">
  <ul class="clear"><img src="<?=$DONO_CASTLE_SIEGE_IMAGE?>" alt="" width="77" height="78" style="border: 2px solid #222222;" /><br /><br /></ul></div>
<div style="margin-top:15px; margin-left:33px; position:absolute;">
  <ul class="clear"><div style="text-align:center; padding:10px;" id="img-cs">
  <img src="<?php echo $CSMark; ?>" alt="Logo da Guild" height="123" width="123" />
                </div></ul></div>
<div class="siege_img"><img src="/{tpldir}images/Siege/siege.png" width="550" height="200" /></div>
<div style="margin-top:110px; margin-left:232px; position:absolute;" class="siege_text" >Dono: <span style="color:#CCC;"><?php echo $CSOwner; ?></span></div>
<div style=" margin-top:149px; margin-left:195px; position:absolute;" class="siege_text">Proximo Confronto: <span style="color:#CCC;"><?php echo $NextCSDate; ?></span></div>
<div style="margin-left:433px; margin-top:110px; width:65px; text-align:center; position:absolute;"><ul class="clear"><div style="color:#CCC; font-size:9px; font-family:gadugi-bold;"><?=$DONO_CASTLE_SIEGE?></div></ul></div>
</div> 
</div>
<a href="http://www.portal.aprendizmuonline.com.br/"><img src="http://www.portal.aprendizmuonline.com.br/images/bannerparcerias/i9naweb-parceria468x60.jpg"title="I9naWEB - portal de muonline, novidades? I9naWEB traz pra voc�!" width="468" height="60" border="0"></a>
            <!-- //Body Center -->